Uec3.initialIndexWindow = Ext.extend(Ext.app.Module, {
   	id: 'initial_index',
   	permissionId:30,
   	objsCollection:new Ext.util.MixedCollection(true),
	getObjByKey:function(key){
		return this.objsCollection.get(key);
	},
	view:function(id){
		this.getObjByKey("OpenOtherWindow")(id);
	},
	del:function(id){
		this.getObjByKey("del")(id);
	},
   getPanel:function() {
   	var module=this;
	// 初始record
	var initial_record = Ext.data.Record.create([{
				name : 'id',
				type : 'int'
			}, {
				name : 'companyId',
				type : 'int'
			}, {
				name : 'creatorId',
				type : 'int'
			}, {
				name : 'submitter',
				type : 'string'
			}, {
				name : 'currentorName',
				type : 'string'
			}, {
				name : 'code',
				type : 'string'
			}, {
				name : 'status',
				type : 'int'
			}, {
				name : 'creatorName',
				type : 'string'
				
			}, {
				name : 'currentorName',
				type : 'string'
			}, {
				name : 'gmtCreate',
				type : 'date',
				dateFormat:'Y-m-d H:i:s'
			}, {
				name : 'gmtSubmit',
				type : 'date',
				dateFormat:'Y-m-d H:i:s'
			}, {
				name : 'amount',
				type : 'float'
			}, {
				name : 'memo',
				type : 'string'
			}]);
	var store = new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : Uec3.App.Constants.homeUrl+'/initial/extList.do'
			}),
			pruneModifiedRecords : true, //
			paramNames : {
				start : "start",
				limit : "limit",
				sort : "sort",
				dir : "dir"   
			},
			remoteSort:true,
			reader : new Ext.data.JsonReader({
				totalProperty : 'totalProperty',
				root : 'root'
				// sortInfo: {field: 'code',
				// direction:'ASC'}
			}, initial_record),
			listeners:{
				
			}
			
	});
	module.objsCollection.add("store",store);
	
	var cm_initial = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),{
				header : '操作',
				width : 80,
				dataIndex:'id',
				renderer:module.moduleActionRenderer([{
					func:'view',
					desc:'操作'
				},{
					func:'del',
					desc:'删除',
					permission:module.permissionId,
					isShow:function(value,metadata,record,rowIndex,store){
						if(record.data.status==0){
							return true;
						}
						return false;
					}
				}])
				}, {
				header : '单据号',
				width : 100,
				sortable : true,
				dataIndex : 'code'
			}, {
				header : '状态',
				width : 80,
				sortable : true,
				dataIndex : 'status',
				// menuDisabled:true,
				renderer : function(v) {return v == false ? '草稿' : '已入库'}
			}, {
				header : '创建人',
				width : 80,
				sortable : true,
				dataIndex : 'creatorName'
			}, {
				header : '当前处理人',
				width : 80,
				sortable : true,
				dataIndex : 'currentorName'
			}, {
				header : '创建时间',
				width : 80,
				sortable : true,
				dataIndex : 'gmtCreate',
				renderer:Ext.util.Format.dateRenderer("Y-m-d")
			}, {
				header : '修改时间',
				width : 80,
				sortable : true,
				dataIndex : 'gmtSubmit',
				renderer:Ext.util.Format.dateRenderer("Y-m-d")
			}, {
				header : '总金额',
				width : 100,
				sortable : true,
				align:"right",
				dataIndex : 'amount'
			}, {
				id:'memo',
				header : '备注',
				width : 300,
				sortable : true,
				maxLength:80,
				dataIndex : 'memo'
			}]);
	var initial_grid = new Ext.grid.GridPanel({
		//id:'initial_grid_Id',
		cm : cm_initial,
		//autoload : true,
		//anchor:'100% 100%',
		store : store,
		columnLines :true,
		selModel : new Ext.grid.RowSelectionModel( {
			moveEditorOnEnter : true
		}),
		iconCls : 'icon-grid',
		loadMask : {
			msg : '数据加载中...'
		},
		stripeRows : true,
		autoScroll : true,
		height : 300,
		width : '100%',
		listeners : {
		},
		autoExpandColumn:'memo',
		bbar: new Ext.PagingToolbar({
            pageSize: 10,
        	store:store,
       	 	displayInfo: true,
        	displayMsg: '第 {0} - {1} 条  共 {2} 条',
        	emptyMsg: "没有记录"
		}),
		tbar : new Ext.Toolbar(['-', {
			text : '新增',
			icon: Uec3.App.Constants.deskUrl+"/resources/images/default/dd/drop-add.gif",
			cls: "x-btn-text-icon",
			handler : function() {
				OpenOtherWindow();
			}
		}]),
		listeners:{
			'afterrender':function(cmp){
			}
		}
	});
	module.objsCollection.add("grid",initial_grid);
	var form_panel=new Ext.FormPanel({
		//autoScroll:true, 
		border:true,
		labelAlign : 'right',
		frame : true,
		labelWidth:80,
		items:[{
				  height:60,
		          layout:'hbox',
		          border:false,
		          layoutConfig: 
		             {     
		               padding:'5',
					   align:'middle' 
                  },            
		          items:[			             
		             {
		               xtype:'label',
		               text:'浏览期初单',
		               style: {font:'bold 30px arial,serif'}
		             },{
		             	xtype:'button',
		             	text: '切换到明细浏览方式',
		             	margins:'0 10',
		             	handler:function changeToReceiveItemBrowser(){	
		             		var desktop =Uec3.App.getDesktop();   
							desktop.launchWindowByParam("initial_viewAllItems"); 
		                       } 
		             },{
                        xtype:'textfield',
                        name:'code',
                        width:200,
                        emptyText : '多条件可用逗号或者空格隔开!'
                     },{
                        xtype:'button',
                        text:'模 糊 查 找',                   
                        margins:'0 30',
                        width:50,
                        handler:searchByCode
                     },{
				  		xtype:'label',
				  		text:'可查条件:单据号,创建人,备注',
				  		style:"color:#ff3333;font-size:14px;margin-left:10px;"
			 		 }]
			
		},initial_grid]
	});
	function getSourceName(value,metadata){
	   var rowIndex = source_comboBox.store.find("varIndex",""+value);   
        if(rowIndex<0) return '请选择..';    
        var record=source_comboBox.store.getAt(rowIndex);   
        return record ? record.get('varName') : '请选择..';   
	}
/*      Ext.util.Observable.capture(initial_grid,function(e){
      	//Ext.MessageBox.alert("grid:",e);
      	if(e=='render'){
      		return false;
      	}
      },null,{preventDefault: true,stopPropagation: true});	*/
	function del(id){
		Ext.Msg.confirm('信息','确定要删除',function(btn){
		 	if(btn=='yes'){
		 		initial_grid.loadMask.show();
			  	Ext.Ajax.request({
			  	url:Uec3.App.Constants.homeUrl+'/initial/delete.do',
			  	params:{'id':id},
        		success:function(response){
	        		var result=Ext.decode(response.responseText);
	        		if(result.success=='OK'){
		        		  var store=initial_grid.getStore();
						  var record=store.getById(id);
						  store.remove(record);
						  store.reload();
	        		}else{
	        		  	  Ext.Msg.alert('信息',result.msg); 
	        		}
	        		initial_grid.loadMask.hide();
        		},
        		failure:function(){
        			Ext.Msg.alert('网络问题');
        			initial_grid.loadMask.hide();
        		}
			  	});
		    }
		});
	}
	this.objsCollection.add("del",del);
	function OpenOtherWindow(id){
		var desktop =Uec3.App.getDesktop();   
		desktop.launchWindowByParam("initial_operation",Ext.type(id)?{id:id,winId:id}:id); 
	}
	this.objsCollection.add("OpenOtherWindow",OpenOtherWindow);
	function searchByCode(){
		var code=form_panel.getForm().findField("code").getValue();
		var store=initial_grid.getStore();
		store.baseParams={searchWordKey:code};
		store.load();
	}
	function showSearchForm(){
		advanced_search_form.form.reset();
	    receive_browser_win.show();
	}
 
	return form_panel;
	},
	initEvent:function(){
		var module=this;
		var win=module.getObjByKey("win");
		win.on('show',function(){
			this.getObjByKey("store").load();
		},module,{single:true});
	},
   createWindow : function(params){
   	  var windowId='initial_index';
   	  if(params){
   	  	windowId+=Ext.isEmpty(params.winId)?"":"_"+params.winId;
   	  }
      var desktop = Uec3.App.getDesktop();
      var module=this;
      var win = desktop.getWindowByUecId(windowId);
      if(!win){
         win = desktop.createWindow({
         	//id:windowId,
            uecId:windowId,
            title: module.launcher.text,
            width:Ext.max([document.body.clientWidth,1000]),
            height: Ext.max([document.body.clientHeight-20,500]),
            iconCls: 'acc-icon',
            shim: false,
            moduleObj:module,
            animCollapse: false,
            constrainHeader: true,
            maximizable: true,
            layout: "fit", 
            items:[Ext.type(params)?this.getPanel():this.getPanel(params)],
            listeners:{
            	'resize':function(win,width,height){
            		var top=this.items.get(0).items.first();
            		var grid=this.items.get(0).items.last();
            		var winMinWidth=1000;
            		var winMinHeight=450;
            		if(width<winMinWidth||height<winMinHeight){
            			win.setWidth(winMinWidth);
            			win.setHeight(winMinHeight);
            			grid.setHeight(winMinHeight-110);
            		}else{
            			grid.setHeight(height-110);
            			
            		}
            	
            	}
            }
         });
         module.objsCollection.add("win",win);
         module.initEvent();
      } 

      win.show();
   }
	});
